/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package All.utility;

/**
 *
 * @author NGUYEN DANG
 */
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.GregorianCalendar;

/**
 *
 * @author Thanh Nhan <JackV at congdongjava.com>
 */
public class DateTimeMaster {

    public static String getHour() {
        Calendar cal = new GregorianCalendar();
        return cal.get(cal.HOUR_OF_DAY) < 10 ? "0" + cal.get(cal.HOUR_OF_DAY) : "" + cal.get(cal.HOUR_OF_DAY);
    }

    public static String getMinute() {
        Calendar cal = new GregorianCalendar();
        return cal.get(cal.MINUTE) < 10 ? "0" + cal.get(cal.MINUTE) : "" + cal.get(cal.MINUTE);
    }

    public static String getSecond() {
        Calendar cal = new GregorianCalendar();
        return cal.get(cal.SECOND) < 10 ? "0" + cal.get(cal.SECOND) : "" + cal.get(cal.SECOND);
    }

    public static String getDate() {
        Calendar cal = new GregorianCalendar();
        return cal.get(cal.DAY_OF_MONTH) < 10 ? "0" + cal.get(cal.DAY_OF_MONTH) : "" + cal.get(cal.DAY_OF_MONTH);
    }

    public static String getMonth() {
        Calendar cal = new GregorianCalendar();
        return (1 + cal.get(cal.MONTH)) < 10 ? "0" + (1 + cal.get(cal.MONTH)) : "" + (1 + cal.get(cal.MONTH));
    }

    public static String getYear() {
        Calendar cal = new GregorianCalendar();
        return cal.get(cal.YEAR) + "";
    }

    public static String getCurrentDateTimeWithDotSeprator() {
        return getHour() + "." + getMinute() + "-" + getDate() + "." + getMonth() + "." + getYear();
    }

    public static String getCurrentDateTime() {
        return getHour() + ":" + getMinute() + "-" + getDate() + "/" + getMonth() + "/" + getYear();
    }

    public static String getCurrentDate() {
        return getDate() + "/" + getMonth() + "/" + getYear();
    }

    public static String getCurrentDateWithDotSeprator() {
        return getDate() + "." + getMonth() + "." + getYear();
    }

    /**
     *
     * @param date is dd/mm/yyyy
     * @return
     */
    public static boolean isValidDate(String date) {
        try {
            SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyy");
            sdf.setLenient(false);
            sdf.parse(date);
        } catch (ParseException e) {
            return false;
        } catch (IllegalArgumentException e) {
            return false;
        }
        return true;
    }
}